package com.yanqu.road.server.logic.activity.condition;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

public abstract class BaseUnionRankActivityCondition extends BaseActivityCondition {

	public BaseUnionRankActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	public final void setUnionRankActivityDefaultValue(String unionUid, int notifyType) {
		if(!StringUtils.isNullOrEmpty(unionUid)) {
			UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(getConditionId());
			setUnionActivityData(unionUid, notifyType, userActivityConditionData);
		}
	}

	public final void setUnionRankActivityValue(BigInteger value, String unionUid, int notifyType) {
		UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(getConditionId());
		userActivityConditionData.setValue(value);
		setUnionActivityData(unionUid, notifyType, userActivityConditionData);
	}

	private void setUnionActivityData(String unionUid, int notifyType, UserActivityConditionData userActivityConditionData) {
		if (UnionRiseRankArgs.NOTIFY_TYPE_NORMAL == notifyType || UnionRiseRankArgs.NOTIFY_TYPE_JOIN == notifyType) {
			userActivityConditionData.setUnionUid(player.getUserInfo().getUnionUid());
		} else if (UnionRiseRankArgs.NOTIFY_TYPE_REMOVE == notifyType || UnionRiseRankArgs.NOTIFY_TYPE_DELETE == notifyType) {
			userActivityConditionData.setUnionUid("");
		}
		UnionActivityMgr.changeUnionActivityValue(activityInfo.getActivityId(), unionUid, player.getUserId(), userActivityConditionData, notifyType);
		player.getModule(ActivityModule.class).onActivityDataChanged(baseActivityData);
	}
}
